<template>
	<view>
		<view class="teamBox">
			<view class="teamContent">
				<view>
					<view style="font-size: 28rpx;color: #333;">我的分销团队</view>
					<view style="color: #0E84FC;font-size: 32rpx;margin-top: 30rpx;">{{teamNum}}人</view>
				</view>
				<image style="width: 280rpx;height: 186rpx;" src="https://qykh.shopec.com.cn/image-server/dz/img_team.png"
					mode=""></image>
			</view>
		</view>

		<view style="background-color: #FFFFFF;margin-top: 20rpx; position: sticky; top: 0;z-index: 2;">
			<u-tabs :list="tabs" ref="tabs" :current="current" keyName="name" @click="change"
				activeColor="{color:#0E84FC}" inactiveColor="{color:#606266}" :scrollable="false">
			</u-tabs>
		</view>

		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="listBox" v-if="list.length > 0">
				<view class="teamItem" v-for="(item,index) in list" :key="index">
					<u-avatar :src="item.vxUrl" size="50"></u-avatar>
					<view class="memberInfo">
						<text class="name">{{item.memberName}}</text>
						<text class="phone">{{item.contactPhone}}</text>
					</view>
				</view>
			</view>
		</mescroll-body>

	</view>
</template>

<script>
	import {
		subordinateCustomers
	} from '@/api/marketing-api.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				current: 0,
				tabs: [{
						name: '一级分销团队',
						type: 1,
					},
					{
						name: '二级分销团队',
						type: 2
					}
				],
				type: 1,
				list: [],
				teamNum : 0
			}
		},
		onLoad(op) {
            this.teamNum = op.teamNum;
		},
		methods: {
			// tab栏切换
			change(item) {
				this.current = item.index;
				this.type = item.type;
				this.mescroll.triggerDownScroll();
			},
			upCallback(page) {
				subordinateCustomers({
					pageNo: page.num,
					pageSize: page.size,
					type: this.type
				}).then(res => {
					this.mescroll.endSuccess(res.data.length);
					//设置列表数据
					if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res.data); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.teamBox {
		height: 270rpx;
		background-image: url('https://qykh.shopec.com.cn/image-server/dz/team_bg.png');
		background-size: 100% 100%;
		padding: 32rpx 22rpx 48rpx;
	}

	.teamContent {
		padding: 44rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #fff;
		border-radius: 24rpx;
	}

	.listBox {
		background-color: #fff;
		padding: 30rpx 36rpx;

		.teamItem {
			background-color: #fff;
			padding: 10rpx 0;
			display: flex;
			align-items: center;

			.memberInfo {
				margin-left: 10rpx;
				font-size: 28rpx;
                display: flex;
                flex-direction: column;
				.name {
					font-weight: 600;
					color: #333333;
				}

				.phone {
					margin-top: 10rpx;
					color: #999999;
				}
			}

		}
	}
</style>
